<?php

namespace app\common\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Db;

class DeleteBehaviorMonitoring extends Command
{

    protected function configure()
    {
        $this->setName('delete_behavior_monitoring')
            ->addArgument('action', Argument::OPTIONAL, "方法名称")
            ->setDescription('删除监测链接');
    }

    protected function execute(Input $input, Output $output)
    {
        $action = $input->getArgument('action');
        if (method_exists($this, $action)) {
            $this->$action();
        }
    }

    public function handler()
    {
        $time= date("Y-m-d 00:00:00",mktime(0,0,0,date("m")-1,date("d"),date("Y")));
        for ($i = 1; $i <= 10000000000; $i++) {
            $list = Db::table('quick_user_behavior_monitoring')->field('id, create_time')->page($i, 1000)->order('id')->select();
            foreach ($list as $value) {
                if ($value['create_time'] >= $time) {
                    exit();
                }
                $r = Db::table('quick_user_behavior_monitoring')->where('id', $value['id'])->delete();
                if ($r) {
                    echo '已删除监测链接编号：【'.$value['id'].'】数据'. PHP_EOL;
                } else {
                    echo '删除监测链接编号：【'.$value['id'].'】数据异常'. PHP_EOL;
                }
            }
        }

    }

}